package ReentrantLock;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @功能
 * @创建时间 2020/5/12
 */
public class ReenTrantLock6 {

    static char[] b = "123456".toCharArray();
    static char[] d = "ABCDEF".toCharArray();
    public static void main(String[] args) {
        Lock lock = new ReentrantLock();
        Condition condition1 = lock.newCondition();
        Condition condition2 = lock.newCondition();
        new Thread(()->{
            try {
            lock.lock();
            for (char i:b) {
                System.out.println(i);

                condition2.signal();

                    condition1.await();

            }
            condition2.signal();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                lock.unlock();
            }
        }).start();
        new Thread(()->{
            try {
            lock.lock();
            for (char i:d) {
                System.out.println(i);
                condition1.signal();

                    condition2.await();

            }
            condition1.signal();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                lock.unlock();
            }
        }).start();

    }
}
